Repository navigation
inline, sink: small loops unroll, a read-once local forwards - #4821
Merged
Merged
Conversation
borisbat
force-pushed
the
loop-unroll
branch
2 times, most recently
from
November 28, 2026 02:36
794363e to
96c0044
Compare
The debugger's if node reports a step at the condition and at the arm it takes. The compare twin reports neither, and the fusion replaced the debugger's node with it, so a stepping session passed over the if. The fusion point now makes no twin for a context that has the debugger on. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
In the interpreter a short loop pays its setup and a node a pass, and a spliced callee leaves locals that are read once. Four rewrites remove that cost. The inliner unrolls a for loop whose passes are known at compile time (a constant range, an array literal of constants, a fixed array) while passes times body statements fits loop_unroll_cost, 8 by default. The loops are planned on the walk that plans the call sites. for [unroll] lifts the limit and for [unroll_disable] keeps one loop. An array literal given to a parameter the body reads once, as a loop source, becomes that loop's source: a fixed array on the stack and no heap array. A callee body that ends in its one return splices with no result local and no scope block. The sink pass replaces a pure local read once in the next statement with its initializer; disable_forward keeps such locals. Nothing with an effect may sit between the two. A function that carries an annotation, and a generated one, keep their loops and locals: a macro may read that body after the optimizer. The shader fixtures set loop_unroll_cost = 0. CodeOfPolicies gains loop_unroll_cost and disable_forward after its last bound field, and dll_search_paths moves behind them. Serializer 291, DAS_POLICIES_VERSION 7, LLVM_JIT_CODEGEN_VERSION 0xCB. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A kernel body is lowered by a shader emitter and never runs in the interpreter, so unrolling its loops and forwarding its locals buys no time and only changes the code the emitter writes. The annotation gate does not reach a helper method or a free function a kernel calls, so each file that holds kernel code sets loop_unroll_cost = 0 and disable_forward: the 26 files with kernel entry points, the shared kernel bodies, the GPU math helpers and the Metal subgroup helpers. The sink pass stays on in them, as it is on master. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
borisbat
force-pushed
the
loop-unroll
branch
from
November 28, 2026 04:05
96c0044 to
39472e7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebuild required:
CodeOfPolicieschanges layout - a host built on the old headers is refused by the ABI stamp (DAS_POLICIES_VERSION7).Why. In the interpreter a short loop pays its setup and a node a pass, and an inlined call leaves locals read once. A four-pass loop over an array literal, through an
[inline]function, cost 51.4 ns and costs 10.9 ns.What changes.
forloop of known passes while passes times body statements fitsloop_unroll_cost(8).returnsplices with no result local.disable_forwardkeeps it.ifover a fused compare stays its own node.Observable behavior.
for (i in range(4)) { s += i }-> four statements, no loop.for [unroll_disable]oroptions loop_unroll_cost = 0-> the loop stays.if (a < b)-> stops at the condition again.Where to look.
unrollLoop(ast_inline.cpp) andforwardLet(ast_sink.cpp): the risk is an evaluation moved past an effect.Validation, claims, ledger
Validation
ci/release_modules.txtmodule set, an AMD Radeon 760M under RADV.make-pr's own gates are green on the pushed tip. The one full run stopped at the fast tier on two gates: five added test lines over the length limit, and the JIT emitter pin, which follows theLLVM_JIT_CODEGEN_VERSIONbump. Both were fixed; each of those gates and every lane the stop skipped then ran once, and the gates and the interpreter, JIT, AOT and C++ lanes ran again afterdisable_forwardwent in.tests-cpp(ctest -L small, which runs the new case intests-cpp/small/test_policies_canary.cpp),tests-interp,tests-jit,tests-aot,watchdog-interp,watchdog-jit,utils-tests,docs/das2rst,docs/stubs.tests-aotwent red once, in the run where all lanes shared the box:tests/lint/test_parallel_equivalence.dastook 64.7 s against the 60 s file budget. Run alone the lane is green, twice, and that file takes 13.8 s.docs/sphinx-htmlis red on the box: 138 warnings, every onevideo: <name>.mp4 is not staged. The box has no GitHub login to fetch the tutorial recordings. No other warning.docs/digestis red on the box with no change from this PR in it: the regeneratedskills/daslang/references/everything.mddiffers from the shipped one in one line, the place ofJobserverin the jobque list.REPORT suite model-free: 84 file(s), 0 failed, 115 cell(s) skipped (a filtered arm, an absent device, or a missing model or fixture - each skips loudly)andREPORT suite gpu-kernels: 5 file(s), 0 failed, 71 cell(s) skipped (a filtered arm, an absent device, or a missing model or fixture - each skips loudly). The box has no models, so no--changed, stocked or category run was made.loop_unroll_cost = 0anddisable_forward; the sink pass stays on in them, as on master. Emitted Vulkan kernels, master against the branch: thegpu-kernelssuite underDASLLAMA_VK_SPV_DUMPon both builds, the dumps compared byharness/vk_spv_diff.das:386 identical, 2 moved, 0 appeared, 0 vanished. The two arekq_batch_k6_mmq_cls_spv(74836 -> 74472 bytes) andkq_batch_k6_mmqs_cls_spv(75360 -> 74996 bytes): the inliner splicesmmq_k6_s8with no result local, so each has two variables, 16 stores and 8 loads fewer, and the same values. Withdisable_sinkin place ofdisable_forwardnine NV4 kernels moved too, because the sink shapesue4m3_half_f32on master. The CUDA and Metal kernel texts were not compared: the box has neither device.loop_unroll_cost = 0anddisable_forwardbeside theirauto_inline_functions = false, since a go-to-definition on an unrolled loop variable or a forwarded local has nothing to land on (utils/mcp/test_tools_navigation.das). The JIT debug-info fixture setsdisable_forward: its test names every local.finallyrefusal, the written loop variable, the foreign generic instance, the macro-owned gate of the forward, thedisable_forwardgate, the optimized-build gate, theurangesource, the callee-write test of a literal element (the test returns 102 for 3 without it), theunsafecallee of the flat splice.35e4fbd8bb, no findings. The commits after it add tests, wrap lines, set the emitter pin and adddisable_forward, one condition in the sink pass.--jit-check-abiwas not run for a cross target: no wasm or ARM build of this tree exists on the box.loop_unroll_costanddisable_forwardsit after every other bound field ofCodeOfPolicies, anddll_search_paths, the one standard-library member that sat in front of bound fields, is now the last member.DAS_POLICIES_VERSION7,LLVM_JIT_CODEGEN_VERSION0xD3 withLLVM_JIT_EMITTER_HASHset again.ARCHITECTURE_INLINE.md#loop-unroll(loopPassValues,InlineCollect::visit(ExprFor),unrollLoop),#inline-loop-source-argument(ParamReadScan,InlineBodyRewriter::visit(ExprFor),stackLiteralForLoopSource),#inline-trailing-return(trailingReturn),ARCHITECTURE_EFFECTS.md#forward-read-once-let(evaluatesAfterPureSiblings,forwardableLet,evaluatesAfterPureSiblingsFrom,forwardLet),#macro-owned-shape(hasMacroOwnedShape,callerAutoCfg) are new, each read against its section, all match.ARCHITECTURE_LOOP_SOURCE.md#stack-loop-literalchanged; its citerstackLoopLiteralmatches.src/simulate/ARCHITECTURE.md#if-over-comparechanged; its citersSimNode_IfCmp, theevalBoolredefinition insimulate_fusion_op2_bool.cppandFusionPoint_IfCmpmatch.tests/optimization/optimization_inline.dastakesdisable_forwardwhole. Its structural tests assert on the temps a splice binds or does not bind: with the forward on, a "no temp" check passes even where the inliner bound one, and the "binds a copy" check oftarget_var_from_letfails. The five local-function tests oftests/ast_match/test_comprehensions.dasmoved totest_local_function_post_inference.das, which carries the option; the rest of that file keeps its options. Intests/gc/test_stackwalk.dasthe invoked block reads its argument twice, so the argument temp the test walks is not forwarded away.[unroll],[unroll_disable],loop_unroll_cost = 0and the optimized-build limit aretest_loop_unroll_firedandtest_loop_unroll_keeps;disable_auto_inlineistest_loop_stays_without_auto_inline;disable_forwardistest_disable_forward_keeps_a_read_once_local; the two host-side policies are the C API case intest_policies_canary.cpp.Claims - stated, not tested
ifkeeps its step. No test observes single steps. Checked by a node dump ofif (a < 5)underoptions debugger:IfLessThenElseArgConstbefore,IfThenElseoverLessArgConstafter, and the fused node again with the guard removed. A break shows as a stepping session that passes over theif.test_loop_stays_without_auto_inlinepasses with the optimized-build gate removed: underdisable_auto_inlinethe patch pass does not run at all. The unoptimized-module test is the one that proves the gate.return, a two-operand operator, aletand anifcondition; the trailingreturnwith a move, a label or a site that stores in place; a renamed local that would shadow an argument in an unrolled body.Not done
mmq_k6_s8twice,fp4_strip_code). Master inlined the same calls with a result local in a block; the values are the same. The Vulkan compare above shows the first two.evaluatesAfterPureSiblingskeeps its own list of parent kinds and does not reusechildrenInEvalOrder. That walk answers a different question, lists more kinds and marks the left of&&eager, so folding the two widens what forwards and needs its own pass over the tree.ast_const_folding.cpp), the read-count lookup and the local-rename setup inast_inline.cpp.exprBodyandflatBodystay two flags.--jit-debuga forwarded local and an unrolled loop variable have no debug record, as an inlined call has no frame.